package com.redtree.air.db
{	
	public class ContactTypes extends Model
	{
		public function ContactTypes()
		{
			super();
			tableName = getTableName('contact_types');
		}
		public function getContactTypes(underSecurity:Boolean=true,justCurrentLevel:Boolean=false):Array
		{
			var sql:String = "select * from contact_types";
			if( underSecurity )
				sql += " where security_level "+(justCurrentLevel?"=":"<=")+" "+currentSecurityLevel;
			if(Model.instance.query(sql))var result:Array = Model.instance.data;
			var resultAry:Array = new Array();
			for( var i:int=0;i<result.length; i++ )
				resultAry.push(new ContactType(result[i]));
			return resultAry;
		}

		public function getContactTypesAsArray(underSecurity:Boolean=true,justCurrentLevel:Boolean=false):Array
		{
			var sql:String = "select name as label,id as data from contact_types";
			if( underSecurity )
				sql += " where security_level "+(justCurrentLevel?"=":"<=")+" "+currentSecurityLevel;
			sql += " ORDER BY seq ASC";
			var result:Array;
			if(Model.instance.query(sql))result = (Model.instance.data);
			return result;
		}

		
	}
}